package com.fqcar.fqdf.ui.main;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.bumptech.glide.Glide;
import com.github.mzule.activityrouter.router.Routers;
import com.fqcar.fqdf.R;
import com.fqcar.fqdf.util.Constants;

import java.util.ArrayList;
import java.util.List;


/**
 * @author 张枭
 * @version V1.0
 * @date 2017/7/25
 * @desc
 */
public class MainDialogHelper {

    private MaterialDialog orderDialog;

    /**
     * 获取orderdialog对话框
     *
     * @param context        上下文内容
     * @param state          状态判断
     * @param orderId        订单ID
     * @param cancelListener 取消按钮的点击事件
     * @return order
     */
    public MaterialDialog getOrderDialog(final Context context, final String state, final String orderId, final DialogOneCallBack cancelListener) {
        if (orderDialog == null) {

            MaterialDialog.Builder orderDialogBuild = new MaterialDialog.Builder(context).canceledOnTouchOutside(false)
                    .positiveColor(context.getResources().getColor(R.color.f)).positiveText("恢复订单")
                    .negativeColor(context.getResources().getColor(R.color.f)).negativeText("取消");
            if (state.equals(Constants.Type.TripOrder.AlreadyReserved)) {//预定中
                orderDialogBuild.content("您有一张预订中订单,是否恢复?");
            } else if (state.equals(Constants.Type.TripOrder.Conducting)) {//进行中
                orderDialogBuild.content("您有一张进行中订单,是否恢复?");
            }

            orderDialog = orderDialogBuild.build();
        }

        orderDialog.getBuilder().onPositive(new MaterialDialog.SingleButtonCallback() {
            @Override
            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                if (state.equals(Constants.Type.TripOrder.AlreadyReserved)) {//有正在进行操作的车辆
//                    Intent intent = new Intent();
//                    intent.setClass(context, StartUseCarHomeNewActivity.class);
//                    intent.putExtra(Constants.Tag.OrderId, orderId);
//                    context.startActivity(intent);
                }
            }
        });
        orderDialog.getBuilder().onNegative(new MaterialDialog.SingleButtonCallback() {
            @Override
            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                cancelListener.btnCallBack();
            }
        });
        return orderDialog;
    }

    /**
     * 显示orderdialog对话框
     *
     * @param context        上下文内容
     * @param state          状态判断
     * @param orderId        订单ID
     * @param cancelListener 取消按钮的点击事件
     */
    public void showOrderDialog(Context context, String state, String orderId, DialogOneCallBack cancelListener) {
        MaterialDialog chargeRule = getOrderDialog(context, state, orderId, cancelListener);
        showDialog(chargeRule);
    }

    /**
     * 隐藏orderdialog对话框
     *
     * @param context        上下文内容
     * @param state          状态判断
     * @param orderId        订单ID
     * @param cancelListener 取消按钮的点击事件
     */
    public void hidenOrderDialog(Context context, String state, String orderId, DialogOneCallBack cancelListener) {
        MaterialDialog chargeRule = getOrderDialog(context, state, orderId, cancelListener);
        hidenDialog(chargeRule);
    }

    /**
     * 隐藏订单dialog
     */
    public void hidenOrderDialog() {
        if (orderDialog != null) {
            hidenDialog(orderDialog);
        }
    }
    /**
     * 显示dialog
     *
     * @param dialog
     */
    private void showDialog(MaterialDialog dialog) {
        if (!dialog.isShowing()) {
            dialog.show();
        }
    }
    private void hidenDialog(MaterialDialog dialog) {
        if (dialog.isShowing()) {
            dialog.dismiss();
        }
    }
}